package demo01;

import java.util.HashMap;
import java.util.Map;

/**
 * 简单的集合缓存
 * */
public class SimpleCache {
	private final  Map cache = new HashMap(); 
	public Object load(String name){
		//略
		return	cache.put(name, new Object());
		 	
	}
	public void clearCache(){
		synchronized(cache){
			cache.clear();
		}
	}
	public Object getObject(String objName){
		Object o;
		synchronized (cache) {
			 o = cache.get(objName);
			if(o==null){
				o = load(objName);
				cache.put(objName, o);
			}
		}
		return o;
		
	}
	
}
